import { View } from "@tarojs/components";
import "./index.scss";

interface ISwitchProps {
  options: API.GradeItem[];
  current: number;
  onChange?: (value: number) => void;
}

const ISwitchIndex: React.FC<ISwitchProps> = (props) => {
  const { options, current = 0, onChange } = props;

  const switchList: API.GradeItem[] = [
    {
      gradeName: "全部",
      gradeCode: 0,
    },
    ...options,
  ];

  return (
    <View className="data_box flex_row">
      {switchList?.map((item) => (
        <View
          className={
            current == item.gradeCode
              ? "switch_item active_item"
              : "switch_item"
          }
          key={item.gradeCode}
          onClick={() => onChange?.(item.gradeCode)}
        >
          {item.gradeName}
        </View>
      ))}
    </View>
  );
};

export default ISwitchIndex;
